<?php

/**
 * This is the model class for table "{{odul}}".
 *
 * The followings are the available columns in table '{{odul}}':
 * @property integer $id
 * @property string $odul
 * @property integer $odul_kategori_id
 * @property string $detay
 */
class Odul extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Odul the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{odul}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('odul_kategori_id, ebeveyn_id', 'numerical', 'integerOnly'=>true),
			array('odul, odul_en, detay, resim_url', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, odul, odul_en, odul_kategori_id, detay, resim_url, ebeveyn_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		return array(
			'kategori'=>array(self::BELONGS_TO, 'OdulKategori', 'odul_kategori_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'odul' => 'Odul',
			'odul_kategori_id' => 'Odul Kategori',
			'detay' => 'Detay',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		$criteria->order = 'odul_kategori_id';
		if(isset($_SESSION["odul_kategori_kriter"])){
			$criteria->addCondition($_SESSION["odul_kategori_kriter"]);
		}

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
			'pagination'=>array(
       	 			'pageSize'=>50,
    		),
		));
	}
}